package com.fosss.band.controller;

import com.fosss.band.entity.Concert;
import com.fosss.band.service.ConcertService;
import com.fosss.band.utils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author: fosss
 * Date: 2024/1/7
 * Time: 23:05
 * Description:
 */
@Api(tags = "演唱会相关接口")
@Slf4j
@RestController
@RequestMapping("/concert")
public class ConcertController {

    @Resource
    private ConcertService concertService;

    @ApiOperation("分页条件查询")
    @GetMapping("/getPageByCondition/{userId}/{page}/{size}")
    public Result getPageByCondition(@PathVariable("userId") Integer userId,
                                     @PathVariable("page") Integer page,
                                     @PathVariable("size") Integer size,
                                     @RequestParam(value = "keyword", required = false) String keyword) {
        log.info("分页条件查询");
        return concertService.getPageByCondition(userId, page, size, keyword);
    }

    @ApiOperation("查询用户参加的演唱会")
    @GetMapping("/getAttendedConcerts/{userId}")
    public Result getAttendedConcerts(@PathVariable("userId") Integer userId) {
        log.info("查询用户参加的演唱会");
        return concertService.getAttendedConcerts(userId);
    }

    @ApiOperation("添加演唱会")
    @PostMapping("/add")
    public Result add(@RequestBody Concert concert) {
        log.info("添加演唱会：{}", concert);
        return concertService.add(concert);
    }

    @ApiOperation("根据演唱会id查询演唱会")
    @GetMapping("/get/{id}")
    public Result get(@PathVariable("id") Integer id) {
        log.info("根据演唱会id查询演唱会：{}", id);
        return concertService.getById(id);
    }

    @ApiOperation("修改演唱会")
    @PutMapping("/update")
    public Result update(@RequestBody Concert concert) {
        log.info("修改演唱会：{}", concert);
        return concertService.update(concert);
    }

    @ApiOperation("删除演唱会")
    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable("id") Integer id) {
        log.info("删除演唱会：{}", id);
        return concertService.delete(id);
    }

    @ApiOperation("根据演唱会id获取参加的歌迷信息")
    @GetMapping("/getFansByConcertId/{id}")
    public Result getFansByConcertId(@PathVariable("id") Integer id) {
        log.info("根据演唱会id获取参加的歌迷信息：{}", id);
        return concertService.getFansByConcertId(id);
    }

    @ApiOperation("参加或退出演唱会")
    @PostMapping("/updateAttendStatus/{fanId}/{concertId}")
    public Result updateAttendStatus(@PathVariable("fanId") Integer fanId, @PathVariable("concertId") Integer concertId) {
        log.info("参加或退出演唱会");
        return concertService.updateAttendStatus(fanId, concertId);
    }
}















